package data_report

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/analysisClient/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SafeBoxRecordReportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 保险箱记录
func NewSafeBoxRecordReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SafeBoxRecordReportLogic {
	return &SafeBoxRecordReportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SafeBoxRecordReportLogic) SafeBoxRecordReport(req *types.SafeBoxRecordRequest) (resp types.SafeBoxResponse, err error) {
	reqq := &rpc.SafeBoxRecordRequest{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		Page:      req.Page,
		PageSize:  req.PageSize,
	}

	analysis, err := l.svcCtx.Analysis.SafeRecordsAnalysis(l.ctx, reqq)
	if err != nil {
		return types.SafeBoxResponse{}, err
	}

	_listt := make([]types.SafeBoxRecord, 0)
	for _, v := range analysis.List {
		t := types.SafeBoxRecord{
			Date:           v.Date,
			InAmount:       v.InAmount,
			OutAmount:      v.OutAmount,
			TradingMargin:  v.TradingMargin,
			MemberIncome:   v.MemberIncome,
			TransferNumber: v.TransferNumber,
		}
		_listt = append(_listt, t)
	}

	resp = types.SafeBoxResponse{
		PageOverall: types.SafeBoxRecord{
			InAmount:       0,
			OutAmount:      0,
			TradingMargin:  0,
			MemberIncome:   0,
			TransferNumber: 0,
		},
		Overall: types.SafeBoxRecord{
			InAmount:       0,
			OutAmount:      0,
			TradingMargin:  0,
			MemberIncome:   0,
			TransferNumber: 0,
		},
		List:     _listt,
		Page:     req.Page,
		PageSize: req.PageSize,
		Total:    analysis.Total,
	}
	return
}
